/*
 * @Author: AskMeWhy
 * @Date: 2020-12-27 11:58:47
 * @Last Modified by: AskMeWhy
 * @Last Modified time: 2020-12-29 11:37:33
 */
const app = getApp();
const { AskComponent } = app._require("common/index");

Component({
    properties: {
        imgSrc: {
            type: String,
            value: "",
        },
        title:{
            type: String,
            value: "", 
        },
        desc:{
            type: String,
            value: "", 
        },
        showTimes:{
            type: Boolean,
            value:true
        },
        items:{
            type: Array,
            value:[]
        },
        indexKey: {
            type: Number,
            value:0,
        }
    },
    data: {
        list:[],
    },
    methods:{
        clickAction(e){
        // console.log(e);
        let item = e.currentTarget.dataset.item;
        // console.log(item);  
        let common_item = e.currentTarget.dataset.item;
        item['type'] = "report";
        let new_item ={"source":""};
        new_item['source'] = item;
        item =    new_item;  
        const userInfo = (app.user && app.user.userInfo) || {};
        // let auth = this.checkAuth();
        // if (!auth) return;
        wx.navigateTo({
            url: "/pages/home/collection/collection-details/index?formId=" + item.source.formId+"&dataCount="+item.source.dataCount+"&processInstanceId="+item.source.processInstanceId+"&userId="+userInfo.id+"&goBackLast=true"+"&type=sb_report",
            success:(e)=>{
                
                //加入缓存
                // let list = this.data.list;
                try {
                    var value = wx.getStorageSync("common_use") || []

                    var isHave = false;
                    value.forEach(element => {
                        if(element.id == common_item.id){
                              //存在？
                              isHave = true;
                        }
                    });

                    if (value.length>5) {
                        if(!isHave){
                            value.splice(value.length-1,1);
                        }
                       
                    }

                    // var isHave = false;
                    // value.forEach(element => {
                    //     if(element.id == common_item.id){
                    //           //加入数据
                    //           isHave = true;
                    //     }
                    // });

                    if(!isHave){
                    value.unshift(common_item);
                          //加入缓存
                    wx.setStorageSync('common_use', value);

                    }
                    let myEventDetail = {
                        arr: value
                    };
                    var myEventOption = {};
                    this.triggerEvent("reloadUse",myEventDetail,myEventOption);    



                  } catch (e) {
                    // Do something when catch error
                  }
                




            }
          });
        },
        shareAction(e){
            // console.log(e);
            try{
            let myEventDetail = e.target.dataset.value;
            var myEventOption = {};
            // console.log(myEventDetail);
             this.triggerEvent("shareAction",myEventDetail,myEventOption);
            }catch(e){
                console.log(e);
            }
            // console.log("-----");
        }
    }

});
